package com.example.spring2301;

import com.example.spring2301.bean.Customer;
import com.example.spring2301.bean.CustomerByAnno;
import com.example.spring2301.bean.MyConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@RequestMapping("/test")
public class Spring2301Application {

    public static void main(String[] args) {
        SpringApplication.run(Spring2301Application.class, args);

//        xml方式装载
//        ApplicationContext context = new ClassPathXmlApplicationContext("myApp.xml");
//        Customer cu1 = (Customer) context.getBean("cu1");
//        System.out.println("用户名=" + cu1.getUsername() +";id=" + cu1.getId() + ";密码=" + cu1.getPassword());

//        注解方式的装载
        ApplicationContext con = new AnnotationConfigApplicationContext(MyConfig.class);
        CustomerByAnno cu22 = con.getBean(CustomerByAnno.class);
        System.out.println("用户名=" + cu22.getUsername() +";id=" + cu22.getId() + ";密码=" + cu22.getPassword());






    }

    @GetMapping("/hello01")
    public String hello() {
        return "hello spring world!";
    }

}
